﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SFJDNotifyIcon
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            ShowInTaskbar = false;
            Visible = false;
            notifyIcon1.Visible = true;
            //启动监听程序
            new SFJDService.SFJDRun();
        }

        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            switch (e.Button)
            {
                case MouseButtons.Left://左键点击图标
                    ShowLeft();
                    break;
                case MouseButtons.Right://右键点击图标
                    //ShowRight(e.X, e.Y);
                    RightMenu();
                    break;
            }
        }

        private void ShowLeft()
        {
            OpenManagement();
        }

        private void RightMenu()
        {
            WindowState = FormWindowState.Normal;
        }

        private void 调试工具ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            new Win_Debug().Show();
        }

        private void 主程序ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenManagement();
        }

        private void OpenManagement()
        {
            bool isStarted = false;
            Process[] pro = Process.GetProcesses();//获取已开启的所有进程
            for (int i = 0; i < pro.Length; i++)//遍历所有查找到的进程
            {
                //判断此进程是否是要查找的进程
                if (pro[i].ProcessName.ToString().ToLower() == "sfjdmanagement")
                {
                    isStarted = true;
                    break;
                }
            }
            if (!isStarted)
            {
                Process p = new Process();
                p.StartInfo.FileName = Environment.CurrentDirectory + "\\SFJDManagement.exe";
                p.Start();
            }
        }
    }
}
